package tenumn.energytech.registrys;

import io.github.uicdb.liba.api.register.BlockHolder;
import io.github.uicdb.liba.api.register.ItemHolder;
import io.github.uicdb.liba.api.register.LazyRegistry;
import io.github.uicdb.liba.api.register.RecipeHolder;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.Block;
import tenumn.energytech.EnergyTech;
import tenumn.energytech.registrys.recipe.GrinderRecipe;
import tenumn.energytech.registrys.recipe.MillingRecipe;


public class RecipeRegistry {
    private static final LazyRegistry registry= EnergyTech.LAZY_REGISTRY;
    public static final RecipeHolder<GrinderRecipe> GRINDER = registry.recipe("grinder",new GrinderRecipe.Ser());
    public static final RecipeHolder<MillingRecipe> MILLING = registry.recipe("milling",new MillingRecipe.Ser());

    public static void init(){
        //在runData时不会触发FMLCommonSetup事件，将代码插入Data事件中
        registry.executeWhenDataStart(()-> {
            registry.dumpRecipe("test",new GrinderRecipe(Ingredient.of(TagRegistry.BRONZE_INGOT), Items.STONE.getDefaultInstance(), Items.STICK.getDefaultInstance(), .5))
                .dumpVanillaRecipe((finishedRecipeConsumer,provider) -> {
                ShapedRecipeBuilder.shaped(ItemRegistry.COPPER_STICK)
                        .pattern("a")
                        .pattern("a")
                        .define('a', Items.COPPER_INGOT)
                        .unlockedBy("hasCopperIngot", provider.hasItem(Items.COPPER_INGOT))
                        .save(finishedRecipeConsumer);
            });
        });
    }
    private static ResourceLocation modLoc(String name){
        return new ResourceLocation(EnergyTech.ID,name);
    }
    private static ItemStack item(Item item){
        return item.getDefaultInstance();
    }
    private static ItemStack item(ItemHolder<?> item){
        return item.get().getDefaultInstance();
    }
    private static ItemStack item(Block block){
        return block.asItem().getDefaultInstance();
    }
    private static ItemStack item(BlockHolder<?> blockHolder){
        return blockHolder.get().asItem().getDefaultInstance();
    }

}
